package days2.middle.title80;

/**
 * @Author fengzihao
 * @Date 2024-04-16 22:19
 */
class Solution {
    public int removeDuplicates(int[] nums) {
        int count = 0;
        int flag = nums[0];
        int num = 0;//flag出现的次数
        int i = 1;
        for (; i < nums.length; i++) {
            if (nums[i]==flag){
                num++;
                if (num>=2)
                    count++;
                else
                    nums[i-count] = nums[i];
            }else {
                flag = nums[i];
                num = 0;
                nums[i-count] = nums[i];
            }
        }
        if (num == 1){
            nums[i-1-count] = nums[i-1];
        }
        return nums.length-count;
    }
}